// JavaScript Document

var dataMonthArray = [9, 15.8, 14, 12, 13.8, 19, 17, 11.7, 9, 15.8, 14, 12, 13.8, 19, 17, 11.7,14, 12, 13.8, 19, 17, 11.7,9,12,13.8,11,10,14,13.9,12];
var dataYearArray = [19, 2, 14, 12, 13.8, 19, 17, 11.7, 9, 15.8, 14, 12];

var singlTime = 0;

//装车，卸车，重驶，空驶单独数据
var zhuangcheTime = 0;
var xiecheTime = 0;
var zhongshiTime = 0;
var kongshiTime = 0;
var kongxianTime = 0;

//装车，卸车，重驶，空驶场站数据
var zhuangcheTimeC = 0;
var xiecheTimeC = 0;
var zhongshiTimeC = 0;
var kongshiTimeC = 0;
var kongxianTimeC = 0;

//选中车辆
var carSelect = "";

//年度月度
var monthYear = "0";

//页面侧边栏操作	
	$(function(){
		$('#vehi-list').on('click','#vehi-list>li',function(){
			$(this).children('ul').slideDown();//中转站点击下拉展开
			$(this).siblings('li').children('ul').slideUp();//其他展开的同时收起
			
		});


        //通过场站id，异步获取车辆信息
        $('.b-botom').click(function () {
            var stationId = $(this).val();
            //ajax start
            $.ajax({
                type: "GET",
                url: "../car/getCarsByStationId",
                dataType : 'json',
                data:{
                    stationId:stationId
                },
                success: function(data){
                    var str = "";
                    $.each(data,function(index, n){
                        var carNo = data[index].carNumber.replace('010','京');
                        str += "<li class='p-bt-10 car' value='"+carNo+"'>"+carNo+"</li>"

                    });
                    $('#carList').html(str);
                }
            });
            //ajax end
        });


        //年度月度切换
        $('.t-c').click(function(){
            var my = $(".twin-bg").html();
            if(my == "年度")
            {
                monthYear = "0";
            }
            else
            {
                monthYear = "1";
            }

            //ajax start
            $.ajax({
                type: "POST",
                url: "../car/getCarDataInfo",
                dataType : 'json',
                data:{
                    carNumber:carSelect,
                    monthYear:monthYear
                },
                success: function(data){
                    dataMonthArray = data.dataMonth;
                    dataYearArray = data.dataYear;
                    singlTime = data.singlTime;
                    kongxianTime = data.kongxianTime;
                    kongxianTimeC = data.kongxianTimeC;

                    zhuangcheTime = data.zhuangcheTime;
                    xiecheTime = data.xiecheTime;
                    zhongshiTime = data.zhongshiTime;
                    kongshiTime = data.kongshiTime;

                    zhuangcheTimeC = data.zhuangcheTimeC;
                    xiecheTimeC = data.xiecheTimeC;
                    zhongshiTimeC = data.zhongshiTimeC;
                    kongshiTimeC = data.kongshiTimeC;
                    // var sumTime = zhuangcheTime+xiecheTime+kongxianTime+zhongshiTime+kongshiTime;
                    // var sumTimeC = zhuangcheTimeC+xiecheTimeC+kongshiTimeC+zhongshiTimeC+kongxianTimeC;
                    var sumTime = (data.days+1) * 24;
                    var sumTimeC = (data.days+1) * 24;
                    // alert(sumTime);
                    var gongshiR = "";

                    kongxianTime = (sumTime-zhuangcheTime-xiecheTime-kongshiTime-zhongshiTime).toFixed(1);

                    chat1();
                    chat2();
                    chat3();
                    chat4();


                    gongshiR += "<tr>";
                    gongshiR += "<td>单车工时</td>";
                    gongshiR += "<td>"+(zhuangcheTime+xiecheTime).toFixed(1)+"</td>";
                    // gongshiR += "<td>"+xiecheTime+"</td>";
                    gongshiR += "<td>"+kongshiTime.toFixed(1)+"</td>";
                    gongshiR += "<td>"+zhongshiTime.toFixed(1)+"</td>";
                    gongshiR += "<td>"+(sumTime-zhuangcheTime-xiecheTime-kongshiTime-zhongshiTime).toFixed(1)+"</td>";
                    gongshiR += "<td>"+sumTime.toFixed(1)+"</td>";
                    gongshiR += "</tr>";

                    gongshiR += "<tr>";
                    gongshiR += "<td>场站平均工时</td>";
                    gongshiR += "<td>"+(zhuangcheTimeC+xiecheTimeC).toFixed(1)+"</td>";
                    // gongshiR += "<td>"+xiecheTimeC+"</td>";
                    gongshiR += "<td>"+kongshiTimeC.toFixed(1)+"</td>";
                    gongshiR += "<td>"+zhongshiTimeC.toFixed(1)+"</td>";
                    gongshiR += "<td>"+(sumTimeC-zhuangcheTimeC-xiecheTimeC-kongshiTimeC-zhongshiTimeC).toFixed(1)+"</td>";
                    gongshiR += "<td>"+sumTimeC.toFixed(1)+"</td>";
                    gongshiR += "</tr>";



                    gongshiR += "<tr>";
                    gongshiR += "<td>单车工时占比</td>";
                    gongshiR += "<td>"+((zhuangcheTime+xiecheTime)*100/sumTime).toFixed(1)+"%</td>";
                    // gongshiR += "<td>"+(xiecheTime*100/sumTime).toFixed(1)+"%</td>";
                    gongshiR += "<td>"+(kongshiTime*100/sumTime).toFixed(1)+"%</td>";
                    gongshiR += "<td>"+(zhongshiTime*100/sumTime).toFixed(1)+"%</td>";
                    gongshiR += "<td>"+((sumTime-zhuangcheTime-xiecheTime-kongshiTime-zhongshiTime)*100/sumTime).toFixed(1)+"%</td>";
                    gongshiR += "<td>100%</td>";
                    gongshiR += "</tr>";

                    gongshiR += "<tr>";
                    gongshiR += "<td>场站平均工时占比</td>";
                    gongshiR += "<td>"+((zhuangcheTimeC+xiecheTimeC)*100/sumTimeC).toFixed(1)+"%</td>";
                    // gongshiR += "<td>"+(xiecheTimeC*100/sumTimeC).toFixed(1)+"%</td>";
                    gongshiR += "<td>"+(kongshiTimeC*100/sumTimeC).toFixed(1)+"%</td>";
                    gongshiR += "<td>"+(zhongshiTimeC*100/sumTimeC).toFixed(1)+"%</td>";
                    gongshiR += "<td>"+((sumTimeC-zhuangcheTimeC-xiecheTimeC-kongshiTimeC-zhongshiTimeC)*100/sumTimeC).toFixed(1)+"%</td>";
                    gongshiR += "<td>100%</td>";
                    gongshiR += "</tr>";

                    $("#gongshiR").html(gongshiR);

                }
            });
            //ajax end

        });


        //选择车辆，查询车辆数据
        $(document).on('click','.car',function(){
        	var carNumber = $(this).attr('name');

            $('.car').css('background-color','#fff');
            $(this).css('background-color','#9cffaa');

            carSelect = carNumber;
            var carstr = "<option>"+carNumber+"</option>";
           $('#scarstring').html(carstr);
            $('#scarstring').attr('name',carNumber);
			//ajax start
            $.ajax({
                type: "POST",
                url: "../car/getCarDataInfo",
                dataType : 'json',
                data:{
                    carNumber:carNumber,
                    monthYear:monthYear
                },
                success: function(data){
                    dataMonthArray = data.dataMonth;
                    dataYearArray = data.dataYear;
                    singlTime = data.singlTime;
                    kongxianTime = data.kongxianTime;
                    kongxianTimeC = data.kongxianTimeC;

                    zhuangcheTime = data.zhuangcheTime;
                    xiecheTime = data.xiecheTime;
                    zhongshiTime = data.zhongshiTime;
                    kongshiTime = data.kongshiTime;

                    zhuangcheTimeC = data.zhuangcheTimeC;
                    xiecheTimeC = data.xiecheTimeC;
                    zhongshiTimeC = data.zhongshiTimeC;
                    kongshiTimeC = data.kongshiTimeC;
                    // var sumTime = zhuangcheTime+xiecheTime+kongxianTime+zhongshiTime+kongshiTime;
                    // var sumTimeC = zhuangcheTimeC+xiecheTimeC+kongshiTimeC+zhongshiTimeC+kongxianTimeC;
                    var sumTime = (data.days+1) * 24;
                    var sumTimeC = (data.days+1) * 24;
                    // alert(sumTime);
                    var gongshiR = "";

                    kongxianTime = (sumTime-zhuangcheTime-xiecheTime-kongshiTime-zhongshiTime).toFixed(1);

                    chat1();
                    chat2();
                    chat3();
                    chat4();


                    gongshiR += "<tr>";
                    gongshiR += "<td>单车工时</td>";
                    gongshiR += "<td>"+(zhuangcheTime+xiecheTime).toFixed(1)+"</td>";
                    // gongshiR += "<td>"+xiecheTime+"</td>";
                    gongshiR += "<td>"+kongshiTime.toFixed(1)+"</td>";
                    gongshiR += "<td>"+zhongshiTime.toFixed(1)+"</td>";
                    gongshiR += "<td>"+(sumTime-zhuangcheTime-xiecheTime-kongshiTime-zhongshiTime).toFixed(1)+"</td>";
                    gongshiR += "<td>"+sumTime.toFixed(1)+"</td>";
                    gongshiR += "</tr>";

                    gongshiR += "<tr>";
                    gongshiR += "<td>场站平均工时</td>";
                    gongshiR += "<td>"+(zhuangcheTimeC+xiecheTimeC).toFixed(1)+"</td>";
                    // gongshiR += "<td>"+xiecheTimeC+"</td>";
                    gongshiR += "<td>"+kongshiTimeC.toFixed(1)+"</td>";
                    gongshiR += "<td>"+zhongshiTimeC.toFixed(1)+"</td>";
                    gongshiR += "<td>"+(sumTimeC-zhuangcheTimeC-xiecheTimeC-kongshiTimeC-zhongshiTimeC).toFixed(1)+"</td>";
                    gongshiR += "<td>"+sumTimeC.toFixed(1)+"</td>";
                    gongshiR += "</tr>";



                    gongshiR += "<tr>";
                    gongshiR += "<td>单车工时占比</td>";
                    gongshiR += "<td>"+((zhuangcheTime+xiecheTime)*100/sumTime).toFixed(1)+"%</td>";
                    // gongshiR += "<td>"+(xiecheTime*100/sumTime).toFixed(1)+"%</td>";
                    gongshiR += "<td>"+(kongshiTime*100/sumTime).toFixed(1)+"%</td>";
                    gongshiR += "<td>"+(zhongshiTime*100/sumTime).toFixed(1)+"%</td>";
                    gongshiR += "<td>"+((sumTime-zhuangcheTime-xiecheTime-kongshiTime-zhongshiTime)*100/sumTime).toFixed(1)+"%</td>";
                    gongshiR += "<td>100%</td>";
                    gongshiR += "</tr>";

                    gongshiR += "<tr>";
                    gongshiR += "<td>场站平均工时占比</td>";
                    gongshiR += "<td>"+((zhuangcheTimeC+xiecheTimeC)*100/sumTimeC).toFixed(1)+"%</td>";
                    // gongshiR += "<td>"+(xiecheTimeC*100/sumTimeC).toFixed(1)+"%</td>";
                    gongshiR += "<td>"+(kongshiTimeC*100/sumTimeC).toFixed(1)+"%</td>";
                    gongshiR += "<td>"+(zhongshiTimeC*100/sumTimeC).toFixed(1)+"%</td>";
                    gongshiR += "<td>"+((sumTimeC-zhuangcheTimeC-xiecheTimeC-kongshiTimeC-zhongshiTimeC)*100/sumTimeC).toFixed(1)+"%</td>";
                    gongshiR += "<td>100%</td>";
                    gongshiR += "</tr>";

                    $("#gongshiR").html(gongshiR);

                }
            });
            //ajax end
        });


		
		window.onload=function(){ 
			var rightHeight = $('.span9').height(),//获取右边栏大小
			    pieRight = $('#pieRight').height();
			$('.span3').height(rightHeight);//让左边栏等值于右边栏
			//$('#pie').height(pieRight+10)//让左边栏等值于右边栏
		}
		
	});

	function chat1() {
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('main'));

        var dataAxis = ['1日','2日','3日','4日','5日','6日','7日','8日','9日','10日','11日','12日','13日','14日','15日','16日','17日','18日','19日','20日','21日','22日','23日','24日','25日','26日','27日','28日','29日','30日','31日'];
        // var data = [9, 15.8, 14, 12, 13.8, 19, 17, 11.7, 9, 15.8, 14, 12, 13.8, 19, 17, 11.7,14, 12, 13.8, 19, 17, 11.7,9,12,13.8,11,10,14,13.9,12];
        var yMax = 24;
        var dataShadow = [];

        for (var i = 0; i < dataMonthArray.length; i++) {
            dataShadow.push(yMax);
        }

        option = {
            backgroundColor:'#fff',
            title: {
                text: '',
                //left:0,
                //top:0,
                //padding:[10,1500,10,50],
                //backgroundColor:'#aed7ad',
            },
            xAxis: {
                data: dataAxis,
                axisLabel: {
                    inside: false,
                    textStyle: {
                        color: '#ccc'
                    }
                },
                axisTick: {
                    show: false
                },
                splitNumber:31,//Y轴分割段数
                axisLine: {
                    show: false
                },
                z: 10
            },
            yAxis: {
                max:24,
                axisLine: {
                    show: false
                },
                axisTick: {
                    show: false
                },
                splitNumber:10,//Y轴分割段数
                axisLabel: {
                    textStyle: {
                        color: '#999'
                    }
                }
            },
            legend: {
                itemWidth:100,
                itemHeight:30,
                orient: 'horizontal',
                left: 'right',
                data: ['月度','年度']
            },
           /* tooltip : {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },*/
            series: [
                {
                    type: 'bar',
                    barWidth: 10,//固定柱子宽度

                    itemStyle: {
                        normal: {
                            label: {
                                show: true,
                                textStyle: {
                                    color: '#9e9e9e'
                                }
                            },
                            color: new echarts.graphic.LinearGradient(
                                0, 0, 0, 1,
                                [
                                    {offset: 0, color: '#6dbb8d'},
                                    {offset: 1, color: '#6dbb8d'}
                                ]
                            )
                        },
                        emphasis: {
                            color: new echarts.graphic.LinearGradient(
                                0, 0, 0, 1,
                                [
                                    {offset: 0, color: '#6dbb8d'},
                                    {offset: 1, color: '#6dbb8d'}
                                ]
                            )
                        }
                    },
                    label: {//柱状体顶端 显示文字
                        normal: {
                            show: true,
                            position: 'top'
                        },
                    },
                    data: dataMonthArray
                }

            ]
        };

        myChart.setOption(option);// 使用刚指定的配置项和数据显示图表// 基于准备好的dom，初始化echarts实例
    }

    function chat2() {
        var myChart = echarts.init(document.getElementById('main1'));

        var dataAxis = ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'];
        // var data = [19, 2, 14, 12, 13.8, 19, 17, 11.7, 9, 15.8, 14, 12];
        var yMax = 720;
        var dataShadow = [];

        for (var i = 0; i < dataYearArray.length; i++) {
            dataShadow.push(yMax);
        }

        option = {
            backgroundColor:'#fff',
            title: {
                text: '',
                //left:0,
                //top:0,
                //padding:[10,1500,10,50],
                //backgroundColor:'#aed7ad',
            },
            xAxis: {
                data: dataAxis,
                axisLabel: {
                    inside: false,
                    textStyle: {
                        color: '#ccc'
                    }
                },
                axisTick: {
                    show: false
                },
                splitNumber:31,//Y轴分割段数
                axisLine: {
                    show: false
                },
                z: 10
            },
            yAxis: {
                max:720,
                axisLine: {
                    show: false
                },
                axisTick: {
                    show: false
                },
                splitNumber:10,//Y轴分割段数
                axisLabel: {
                    textStyle: {
                        color: '#999'
                    }
                }
            },
            legend: {
                itemWidth:100,
                itemHeight:30,
                orient: 'horizontal',
                left: 'right',
                data: ['月度','年度']
            },
            tooltip : {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            series: [
                {
                    type: 'bar',
                    barWidth: 10,//固定柱子宽度

                    itemStyle: {
                        normal: {
                            label: {
                                show: true,
                                textStyle: {
                                    color: '#9e9e9e'
                                }
                            },
                            color: new echarts.graphic.LinearGradient(
                                0, 0, 0, 1,
                                [
                                    {offset: 0, color: '#6dbb8d'},
                                    {offset: 1, color: '#6dbb8d'}
                                ]
                            )
                        },
                        emphasis: {
                            color: new echarts.graphic.LinearGradient(
                                0, 0, 0, 1,
                                [
                                    {offset: 0, color: '#6dbb8d'},
                                    {offset: 1, color: '#6dbb8d'}
                                ]
                            )
                        }
                    },
                    label: {//柱状体顶端 显示文字
                        normal: {
                            show: true,
                            position: 'top'
                        },
                    },
                    data: dataYearArray
                }

            ]
        };

        myChart.setOption(option);// 使用刚指定的配置项和数据显示图表
    }

	function chat3() {
        //2，以下是单车工时饼图
        var myChart2 = echarts.init(document.getElementById('part1'));
        option = {
            height:250,
            title : {
                text: '',
                //left:0,
                //top:0,
                //padding:[10,1500,10,20],
            },
            //legend: {
            //	orient: 'horizontal',
            //	top:40,
            //left: 10,
            //data: ['空闲工时','有效工时']
            //},
            tooltip : {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            series : [
                {
                    // name: '',
                    type: 'pie',
                    radius : '70%',
                    center: ['50%', '50%'],

                    label: {
                        normal: {
                            position: 'inner',
                            fontSize: 12
                        }
                    },
                    data:[
                        {value:kongxianTime, name:'空闲工时'+kongxianTime+'h'},
                        {value:singlTime, name:'有效工时'+singlTime+'h'}
                    ],
                    itemStyle: {
                        emphasis: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        },
                        labelLine: {
                            normal:{
                                show:true,
                                length:'1',
                                length2:'10'
                            }
                        },
                    }

                }
            ],
            color: ['#d85f42','#ed9a72']
        };
        myChart2.setOption(option);
    }

	
	function chat4() {
        //3，以下是装卸车饼图
        var myChart3 = echarts.init(document.getElementById('part2'));
        option = {
            height:250,
            title : {
                x:'center'
            },
            tooltip : {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            //legend: {
            //orient: 'horizontal',
            //top:40,
            ///left: 'left',
            //data: ['装车','卸车','重驶','空驶'],
            //},
            series : [
                {
                    // name: '',
                    type: 'pie',
                    radius : '70%',
                    center: ['50%', '50%'],

                    label: {
                        normal: {
                            position: 'inner'
                        }
                    },
                    data:[
                        {value:zhuangcheTime+xiecheTime, name:'装卸车'},
                        // {value:xiecheTime, name:'卸车'},
                        {value:zhongshiTime, name:'重驶'},
                        {value:kongshiTime, name:'空驶'},
                    ],
                    itemStyle: {
                        emphasis: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                }
            ],
            color: ['#d85f42','#f7e2cf','#ed9a72','#f1f0ec']
        };
        myChart3.setOption(option);
    }

				

